package com.uniview.controller;

import com.uniview.dto.RespDTO;
import com.uniview.exception.CommonException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * created by lux
 */
@RefreshScope
@RestController
public class ErrorController {
    @Autowired
    Environment environment;
    @RequestMapping("/errorTest")
    public void testError() throws Exception{
        throw new CommonException("1234","测试网关抛错");
    }

    @RequestMapping("/testValue")
    public RespDTO testValue(){
        return RespDTO.onSuc(environment.getProperty("config.test"));
    }

    @RequestMapping("/testReturn")
    public Map<String,Object> testReturn(@RequestParam("test") String test) throws Exception{
        Map<String,Object> map = new HashMap<>();
        map.put("test",test);
        map.put("test1","hahah");
        return map;
    }
    @RequestMapping("/testBody")
    public RespDTO<Map<String,Object>> testBody(@RequestBody Map<String,Object> test) throws Exception{
        Map<String,Object> map = new HashMap<>();
        map.put("test",test);
        map.put("test1","testBody");
        return RespDTO.onSuc(map);
    }

}
